package com.tqfframe.website.web.controller;

import com.tqfframe.website.web.common.Result;
import com.tqfframe.website.web.entry.StockEntity;
import com.tqfframe.website.web.service.StockService;
import com.tqfframe.website.web.vo.StockDTO;
import com.tqfframe.website.web.vo.StockInfoDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Tang-QiFeng on 2021/1/2
 */
@RestController
public class StockController {

    Logger logger = LoggerFactory.getLogger(StockController.class);

    @Autowired
    private StockService stockService;

    /**
     *   http://localhost:9001/getTodayData
     *
     * @return
     */
    @GetMapping(value = "/getTodayData")
    public List<StockInfoDTO> getTodayData(){
        List<StockInfoDTO> list=stockService.getTodtayData();
        return list;
    }


    /**
     *   http://localhost:9001/getKValueById/sh600686
     *
     * @return
     */
    @GetMapping(value = "/getKValueById/{id}")
    public List<StockDTO> getKValueById(@PathVariable(name = "id") String id){
        System.out.println(id);
        List<StockDTO> list=stockService.getKValueById(id);
        return list;
    }



    /**
     *
     * @return
     */
    @GetMapping(value = "/getProcessedNum")
    public Integer getProcessedNum(){
        return stockService.getExcuteNum();
    }



    /**
      *     当天股票K值入库
     *   http://localhost:9001/executeK
      *
     * @return
     */
    @GetMapping(value = "/executeK")
    public Result executeK(){
//        System.out.println("111");
//        return new Result();
        return stockService.executeK();
    }
//
//     /**
//      * 录入股票代码，添加当日股票K值
//     *   http://localhost:9001/insertStock/sh601688/11.30
//     *      no     =股票编码    深圳：sz002273    上海：sh601688
//     *     value   =k值
//     *
//     * @return
//     */
//    @GetMapping(value = "/insertStock/{no}/{value}")
//    public Result insertStock(@PathVariable String no, @PathVariable String value){
//        return stockService.insertStock(no,value);
//    }


    /**
     * 修改龙头标记
     *
     * @return
     */
    @GetMapping(value = "/updateStock/{id}/{value}")
    public Result updateStock(@PathVariable String id, @PathVariable String value){
        return stockService.updateStock(id,value);
    }

     /**
      * 录入股票代码，添加当日股票K值
     *   http://localhost:9001/insertPostStock
     *      no     =股票编码    深圳：sz002273    上海：sh601688
     *     value   =k值
     *
     * @return
     */
    @PostMapping(value = "/insertPostStock")
    public Result insertPostStock(StockEntity stockEntity){
        return stockService.insertStock(stockEntity.getStockNo(),stockEntity.getKValue()+"");
    }

}
